package com.community.controller;

import com.community.base.BaseController;
import com.community.common.Const;
import com.community.common.ServerResponse;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 问题控制层
 */
@RestController
@RequestMapping("/questionController/")
@CrossOrigin(origins = Const.REQUESTURL,maxAge = 3600,allowCredentials = "true")
public class QuestionController extends BaseController {

    /**
     * 条件查询提问（一般用于问题分类，如悬赏，热门等）
     * @param pageNum
     * @param request
     * @return
     */
    @GetMapping("selectQuesionByParam.do")
    public ServerResponse<PageInfo> selectQuesionByParam(@RequestParam(value = "pageNum") int pageNum,
                                                        @RequestParam(value = "questionType") int questionType,
                                                        HttpServletRequest request){
        return iQuestionService.selectByParam(pageNum,questionType,request);
    }

    /**
     * 新增提问
     * @param paramMap
     * @param request
     * @return
     */
    @PostMapping("add.do")
    public ServerResponse<String> add(@RequestParam Map paramMap,HttpServletRequest request){
        return iQuestionService.add(paramMap,request);
    }

    /**
     * 更新提问信息
     * @param paramMap
     * @param request
     * @return
     */
    @PostMapping("update.do")
    public ServerResponse<String> update(@RequestParam Map paramMap,HttpServletRequest request){
        return iQuestionService.update(paramMap,request);
    }

    /**
     * 根据ID查询问题详情
     * @param id
     * @return
     */
    @GetMapping("selectById.do")
    public ServerResponse<Map> selectById(@RequestParam(value = "id") Integer id,HttpServletRequest request){
        return iQuestionService.selectById(id,request);
    }

    /**
     * 查询付费答案
     * @param questionId
     * @param request
     * @return
     */
    @GetMapping("selectQuestionAnswer.do")
    public ServerResponse<List<Map>> selectQuestionAnswer(@RequestParam(value = "questionId") Integer questionId, HttpServletRequest request){
        return iQuestionService.selectQuestionAnswer(questionId,request);
    }
}
